package cn.hzxs.zjn.studentmanagement.dao;

import cn.hzxs.zjn.studentmanagement.domain.Page;
import cn.hzxs.zjn.studentmanagement.domain.Plan;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: Zjn *Bring it on!!!*
 * @Date: 2021/3/28 14:30
 * Note:
 */
@Repository
public interface PlanMapper {


    @Results(id = "PlanMap", value = {
            @Result(column = "plan_id", property = "PLANID", javaType = Integer.class),
            @Result(column = "plan_authorid", property = "PLANAUTHORID", javaType = Integer.class),
            @Result(column = "plan_title", property = "PLANTITLE", javaType = String.class),
            @Result(column = "plan_detail", property = "PLANDETAIL", javaType = String.class),
            @Result(column = "type", property = "TYPE", javaType = String.class),
            @Result(column = "create_time", property = "CREATETIME", javaType = String.class),
            @Result(column = "update_time", property = "UPDATETIME", javaType = String.class),
            @Result(column = "user_name", property = "USERNAME", javaType = String.class),
            @Result(column = "user_icon", property = "USERICON", javaType = String.class),
    })
    /*获取所有人计划*/

    @Select("select u.user_name,u.user_icon,p.plan_authorid,p.plan_id,p.plan_title," +
            "p.plan_detail,p.create_time from user u,plan p" +
            " where p.plan_authorid=#{plan.PLANAUTHORID} and u.user_id=#{plan.PLANAUTHORID}" +
            " and p.type=#{plan.TYPE};")
    List<Plan> getPlanByAuthorId(@Param("plan") Plan plan);


    /*添加个人计划*/
    @Insert("insert into plan (plan_authorid,plan_title,plan_detail,type,create_time,update_time) " +
            " values (#{plan.PLANAUTHORID},#{plan.PLANTITLE},#{plan.PLANDETAIL}," +
            "#{plan.TYPE},current_date(),current_date());")
    @ResultMap(value = "PlanMap")
    void addPlan(@Param("plan") Plan plan);


    /*获取计划*/
    @Select("select plan_id,plan_authorid,plan_title,plan_detail,type,user_name,user_icon,create_time from plan,user" +
            " where plan_authorid=user_id limit #{page.OFFSET},#{page.LIMIT};")
    @ResultMap(value = "PlanMap")
    List<Plan> getPlan(@Param("page") Page page);


}
